home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / axserver.c < prev    next >
C/C++ Source or Header  |  1991-03-29  |  2KB  |  87 lines

  1. /* @(#) $Header: axserver.c,v 1.7 91/03/28 19:39:16 deyke Exp $ */
  2.  
  3. #include <stdlib.h>
  4.  
  5. #include "global.h"
  6. #include "timer.h"
  7. #include "ax25.h"
  8. #include "lapb.h"
  9. #include "login.h"
  10.  
  11. static void axserv_recv_upcall __ARGS((struct ax25_cb *cp, int cnt));
  12. static void axserv_send_upcall __ARGS((struct ax25_cb *cp, int cnt));
  13. static void axserv_state_upcall __ARGS((struct ax25_cb *cp, int oldstate, int newstate));
  14.  
  15. /*---------------------------------------------------------------------------*/
  16.  
  17. static void axserv_recv_upcall(cp, cnt)
  18. struct ax25_cb *cp;
  19. int  cnt;
  20. {
  21.   struct mbuf *bp;
  22.  
  23.   recv_ax(cp, &bp, 0);
  24.   login_write((struct login_cb *) cp->user, bp);
  25. }
  26.  
  27. /*---------------------------------------------------------------------------*/
  28.  
  29. static void axserv_send_upcall(cp, cnt)
  30. struct ax25_cb *cp;
  31. int  cnt;
  32. {
  33.   struct mbuf *bp;
  34.  
  35.   if (bp = login_read((struct login_cb *) cp->user, space_ax(cp)))
  36.     send_ax(cp, bp);
  37. }
  38.  
  39. /*---------------------------------------------------------------------------*/
  40.  
  41. static void axserv_state_upcall(cp, oldstate, newstate)
  42. struct ax25_cb *cp;
  43. int  oldstate, newstate;
  44. {
  45.   char  callsign[AXBUF];
  46.  
  47.   switch (newstate) {
  48.   case CONNECTED:
  49.     pax25(callsign, cp->hdr.dest);
  50.     cp->user = (char *) login_open(callsign, "AX25", (void (*)()) axserv_send_upcall, (void (*)()) close_ax, cp);
  51.     if (!cp->user) close_ax(cp);
  52.     break;
  53.   case DISCONNECTED:
  54.     login_close((struct login_cb *) cp->user);
  55.     del_ax(cp);
  56.     break;
  57.   }
  58. }
  59.  
  60. /*---------------------------------------------------------------------------*/
  61.  
  62. int  ax250(argc, argv, p)
  63. int  argc;
  64. char  *argv[];
  65. void *p;
  66. {
  67.   if (axcb_server) {
  68.     free(axcb_server);
  69.     axcb_server = NULLAXCB;
  70.   }
  71.   return 0;
  72. }
  73.  
  74. /*---------------------------------------------------------------------------*/
  75.  
  76. int  ax25start(argc, argv, p)
  77. int  argc;
  78. char  *argv[];
  79. void *p;
  80. {
  81.   if (!axcb_server)
  82.     axcb_server = open_ax(NULLCHAR, AX_SERVER, axserv_recv_upcall,
  83.               axserv_send_upcall, axserv_state_upcall, NULLCHAR);
  84.   return axcb_server ? 0 : -1;
  85. }
  86.  
  87.